package hcontroller

import (
	"encoding/json"

	"advertoper/controllers"
	"advertoper/errorcode"
	"advertoper/homepageinfo/hservice"
)

type ZJPictureInfoController struct {
	controllers.SCLoginedController
}

/*添加Picture图片
{"region_code":"all","size":"655:580",
"pic_url":"https://fscdn.qkier.com/scloud/e/b/c/d725bad2001dd6c76a189dd6e0f69",
"starttick":1,"endtick":1499999999}
*/
// @router /zjpicture/add [post]
func (p *ZJPictureInfoController) PictureAdd() {
	defer p.Output("PictureAdd")
	p.ForceHTTPS()

	body := p.Ctx.Input.RequestBody
	req := &hservice.ZJPictureAdd{}
	if err := json.Unmarshal(body, req); err != nil {
		p.Resp["code"] = errorcode.EC_GL_INVALID_JSON_BODY
		p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_INVALID_JSON_BODY)
		return
	}
	code, msg := hservice.GetZJPictureInfoService().PictureAdd(req)
	p.Resp["code"] = code
	p.Resp["msg"] = msg

}

/*修改Picture图片
 */
// @router /zjpicture/update [post]
func (p *ZJPictureInfoController) PictureUpdate() {
	defer p.Output("PictureUpdate")
	p.ForceHTTPS()

	body := p.Ctx.Input.RequestBody
	req := &hservice.ZJPictureUpdate{}
	if err := json.Unmarshal(body, req); err != nil {
		p.Resp["code"] = errorcode.EC_GL_INVALID_JSON_BODY
		p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_INVALID_JSON_BODY)
		return
	}
	code, msg := hservice.GetZJPictureInfoService().PictureUpdate(req)
	p.Resp["code"] = code
	p.Resp["msg"] = msg

}

//web查询
// @router /zjpicture/list [get]
func (p *ZJPictureInfoController) PictureList() {
	defer p.Output("PictureList")
	p.ForceHTTPS()

	status, _ := p.GetInt("status", 1)
	data := hservice.GetZJPictureInfoService().PictureList(status)
	if len(data) == 0 {
		p.Resp["code"] = 101
		p.Resp["msg"] = "no data"
	} else {
		p.Resp["code"] = 0
		p.Resp["msg"] = "success"
		p.Resp["data"] = data
	}

}
